package com.ffcs.cn.action.common;

import com.supermap.desktop.controls.ui.controls.colorSelect.SmButtonColorSelector;
import com.supermap.desktop.core.event.colorSelect.IColorChangedListener;
import com.supermap.desktop.core.ui.controls.GridBagConstraintsHelper;
import com.supermap.desktop.core.ui.controls.SMSpinner;
import com.ffcs.cn.DevelopProperties;

import javax.swing.*;
import javax.swing.event.ChangeListener;
import java.awt.*;

/**
 * 线对象风格设置面板
 *
  */
public abstract class StyleSettingPaneLine extends AbstractStyleSettingPanel {
	protected JLabel jLabelLineColor;
	protected SmButtonColorSelector buttonLineColor;

	protected JLabel jLabelLineWidth;
	protected SMSpinner spinnerLineWidth;

	public StyleSettingPaneLine() {
		jLabelLineColor = new JLabel(DevelopProperties.getString("String_Label_LineColor"));
		buttonLineColor = new SmButtonColorSelector();

		jLabelLineWidth = new JLabel(DevelopProperties.getString("String_Label_LineWidth"));
		spinnerLineWidth = new SMSpinner(new SpinnerNumberModel(0.0, 0.0, 50.0, 0.1));
		initLayout();
		registerEvents();
	}

	private void initLayout() {
		this.setLayout(new GridBagLayout());
		this.add(jLabelLineColor, new GridBagConstraintsHelper(0, 0, 1, 1)
				.setAnchor(GridBagConstraints.WEST)
				.setInsets(GridBagConstraintsHelper.CONTROLS_GAP, GridBagConstraintsHelper.FRAME_CONTROL_GAP, GridBagConstraintsHelper.CONTROLS_GAP, GridBagConstraintsHelper.FRAME_CONTROL_GAP)
				.setFill(GridBagConstraints.NONE)
				.setWeight(0, 0));
		this.add(buttonLineColor, new GridBagConstraintsHelper(1, 0, 2, 1)
				.setInsets(GridBagConstraintsHelper.CONTROLS_GAP, GridBagConstraintsHelper.CONTROLS_GAP, GridBagConstraintsHelper.CONTROLS_GAP, GridBagConstraintsHelper.CONTROLS_GAP)
				.setAnchor(GridBagConstraints.WEST)
				.setFill(GridBagConstraints.HORIZONTAL)
				.setWeight(1, 0));
		this.add(jLabelLineWidth, new GridBagConstraintsHelper(0, 1, 1, 1)
				.setAnchor(GridBagConstraints.WEST)
				.setInsets(GridBagConstraintsHelper.CONTROLS_GAP, GridBagConstraintsHelper.FRAME_CONTROL_GAP, GridBagConstraintsHelper.CONTROLS_GAP, GridBagConstraintsHelper.FRAME_CONTROL_GAP)
				.setFill(GridBagConstraints.NONE)
				.setWeight(0, 0));
		this.add(spinnerLineWidth, new GridBagConstraintsHelper(1, 1, 2, 1)
				.setInsets(GridBagConstraintsHelper.CONTROLS_GAP, GridBagConstraintsHelper.CONTROLS_GAP, GridBagConstraintsHelper.CONTROLS_GAP, GridBagConstraintsHelper.CONTROLS_GAP)
				.setAnchor(GridBagConstraints.WEST)
				.setFill(GridBagConstraints.HORIZONTAL)
				.setWeight(1, 0));
	}

	private void registerEvents() {
		buttonLineColor.addColorChangedListener(getLineColorChangedListener());
		spinnerLineWidth.addChangeListener(getLineWidthChangeListener());

	}

	/**
	 * 获取线颜色值改变的监听器
	 *
	 * @return 监听器
	 */
	public abstract IColorChangedListener getLineColorChangedListener();

	/**
	 * 获取线宽度改变的监听器
	 *
	 * @return 监听器
	 */
	public abstract ChangeListener getLineWidthChangeListener();

}
